package com.guofen;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2 {
    /**
     * 创建API应用
     * apiInfo() 增加API相关信息
     * 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现，
     * 本例采用指定扫描的包路径来定义指定要建立API的目录。
     *
     * @return
     */
    @Bean("shlj")
    public Docket createRest1Api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("生活垃圾")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.guofen.controller.shlj"))
                .paths(PathSelectors.any())
                .build();
    }
    @Bean("cylj")
    public Docket createRest2Api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("厨余垃圾")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.guofen.controller.cylj"))
                .paths(PathSelectors.any())
                .build();
    }
    @Bean("yf")
    public Docket createRest3Api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("研发")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.guofen.controller.yf"))
                .paths(PathSelectors.any())
                .build();
    }
    @Bean("sjq")
    public Docket createRest4Api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("四季青")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.guofen.controller.sjq"))
                .paths(PathSelectors.any())
                .build();
    }
    @Bean("hsmpy")
    public Docket createRest5Api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("黑水虻培育")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.guofen.controller.hsmpy"))
                .paths(PathSelectors.any())
                .build();
    }
    @Bean("user")
    public Docket createRest6Api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("用户管理")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.guofen.controller.user"))
                .paths(PathSelectors.any())
                .build();
    }
    @Bean("name")
    public Docket createRest7Api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("在UTA assignment")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.guofen.controller.name"))
                .paths(PathSelectors.any())
                .build();
    }
    @Bean("sjck")
    public Docket createRest8Api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("数据出库和温湿度数据展示")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.guofen.controller.sjck"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 创建该API的基本信息（这些基本信息会展现在文档页面中）
     * 访问地址：http://项目实际地址/swagger-ui.html
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("测试Swagger项目")
                .description("无")
                .termsOfServiceUrl("")
                .version("1.0")
                .build();
    }

}